<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>docker 安装 | 海内存知已，天涯若比邻</title><meta name="keywords" content="docker"><meta name="author" content="mowei"><meta name="copyright" content="mowei"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="一、Docker 安装1.卸载旧版本12345678yum remove docker \    docker-client \    docker-client-latest \    docker-common \    docker-latest \    docker-latest-logrotate \    docker-logrotate \    docker-engine 2.y">
<meta property="og:type" content="article">
<meta property="og:title" content="docker 安装">
<meta property="og:url" content="https://gitee.com/momomomowei/blog/docker/docker%20%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85/index.html">
<meta property="og:site_name" content="海内存知已，天涯若比邻">
<meta property="og:description" content="一、Docker 安装1.卸载旧版本12345678yum remove docker \    docker-client \    docker-client-latest \    docker-common \    docker-latest \    docker-latest-logrotate \    docker-logrotate \    docker-engine 2.y">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/momomomowei/images/docker_cover.jpeg">
<meta property="article:published_time" content="2023-03-18T06:06:43.000Z">
<meta property="article:modified_time" content="2024-04-21T07:24:14.361Z">
<meta property="article:author" content="mowei">
<meta property="article:tag" content="docker">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/momomomowei/images/docker_cover.jpeg"><link rel="shortcut icon" href="/media/favicon.png"><link rel="canonical" href="https://gitee.com/momomomowei/blog/docker/docker%20%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'docker 安装',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-04-21 15:24:14'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    document.addEventListener('pjax:complete', detectApple)})(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/media/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">41</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">29</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 目录</span><i class="fas fa-chevron-down expand hide"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/images/docker_cover.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">海内存知已，天涯若比邻</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 目录</span><i class="fas fa-chevron-down expand hide"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">docker 安装</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-03-18T06:06:43.000Z" title="发表于 2023-03-18 14:06:43">2023-03-18</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-04-21T07:24:14.361Z" title="更新于 2024-04-21 15:24:14">2024-04-21</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/docker/">docker</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">3.3k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>13分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="docker 安装"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="一、Docker-安装"><a href="#一、Docker-安装" class="headerlink" title="一、Docker 安装"></a>一、Docker 安装</h1><h2 id="1-卸载旧版本"><a href="#1-卸载旧版本" class="headerlink" title="1.卸载旧版本"></a>1.卸载旧版本</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">yum remove docker \</span><br><span class="line">    docker-client \</span><br><span class="line">    docker-client-latest \</span><br><span class="line">    docker-common \</span><br><span class="line">    docker-latest \</span><br><span class="line">    docker-latest-logrotate \</span><br><span class="line">    docker-logrotate \</span><br><span class="line">    docker-engine</span><br></pre></td></tr></table></figure>
<h2 id="2-yum安装gcc相关"><a href="#2-yum安装gcc相关" class="headerlink" title="2.yum安装gcc相关"></a>2.yum安装gcc相关</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum -y install gcc</span><br><span class="line">yum -y install gcc-c++</span><br><span class="line">yum install -y yum-utils</span><br></pre></td></tr></table></figure>
<h2 id="3-设置stable镜像仓库"><a href="#3-设置stable镜像仓库" class="headerlink" title="3.设置stable镜像仓库"></a>3.设置stable镜像仓库</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</span><br></pre></td></tr></table></figure>
<h2 id="4-更新yum软件包索引"><a href="#4-更新yum软件包索引" class="headerlink" title="4.更新yum软件包索引"></a>4.更新yum软件包索引</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum makecache fast</span><br></pre></td></tr></table></figure>
<h2 id="5-安装DOCKER-CE"><a href="#5-安装DOCKER-CE" class="headerlink" title="5.安装DOCKER CE"></a>5.安装DOCKER CE</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum -y install docker-ce docker-ce-cli containerd.io</span><br></pre></td></tr></table></figure>
<h2 id="6-启动docker"><a href="#6-启动docker" class="headerlink" title="6.启动docker"></a>6.启动docker</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">systemctl start docker</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">systemctl daemon-reload</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">systemctl restart docker</span></span><br></pre></td></tr></table></figure>
<h2 id="7-测试"><a href="#7-测试" class="headerlink" title="7.测试"></a>7.测试</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker version</span><br><span class="line">docker run hello-world</span><br></pre></td></tr></table></figure>
<h2 id="8-卸载"><a href="#8-卸载" class="headerlink" title="8.卸载"></a>8.卸载</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">systemctl stop docker </span><br><span class="line">yum remove docker-ce docker-ce-cli containerd.io</span><br><span class="line">rm -rf /var/lib/docker</span><br><span class="line">rm -rf /var/lib/containerd</span><br></pre></td></tr></table></figure>
<h2 id="9-阿里云镜像加速"><a href="#9-阿里云镜像加速" class="headerlink" title="9.阿里云镜像加速"></a>9.阿里云镜像加速</h2><blockquote>
<p>可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">登陆阿里云开发者平台</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">点击控制台</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">选择容器镜像服务</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">镜像工具</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">镜像加速器</span></span><br><span class="line"></span><br><span class="line">sudo mkdir -p /etc/docker</span><br><span class="line"></span><br><span class="line">sudo tee /etc/docker/daemon.json &lt;&lt;-&#x27;EOF&#x27;</span><br><span class="line">&#123;</span><br><span class="line">    &quot;registry-mirrors&quot;: [</span><br><span class="line">        &quot;https://ustc-edu-cn.mirror.aliyuncs.com&quot;,</span><br><span class="line">        &quot;http://hub-mirror.c.163.com&quot;,</span><br><span class="line">        &quot;https://registry.aliyuncs.com&quot;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line">EOF</span><br><span class="line"></span><br><span class="line">sudo systemctl daemon-reload</span><br><span class="line">sudo systemctl restart docker</span><br></pre></td></tr></table></figure>
<h1 id="二、Docker-常用命令"><a href="#二、Docker-常用命令" class="headerlink" title="二、Docker 常用命令"></a>二、Docker 常用命令</h1><h2 id="1-帮助启动类命令"><a href="#1-帮助启动类命令" class="headerlink" title="1.帮助启动类命令"></a>1.帮助启动类命令</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">启动docker：</span> </span><br><span class="line">systemctl start docker</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">停止docker：</span> </span><br><span class="line">systemctl stop docker</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">重启docker：</span> </span><br><span class="line">systemctl restart docker</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看docker状态：</span> </span><br><span class="line">systemctl status docker</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">开机启动：</span> </span><br><span class="line">systemctl enable docker</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看docker概要信息：</span> </span><br><span class="line">docker info</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看docker总体帮助文档：</span> </span><br><span class="line">docker --help</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看docker命令帮助文档：</span> </span><br><span class="line">docker 具体命令 --help</span><br></pre></td></tr></table></figure>
<h2 id="2-镜像命令"><a href="#2-镜像命令" class="headerlink" title="2.镜像命令"></a>2.镜像命令</h2><blockquote>
<p>同一仓库源可以有多个 TAG版本，代表这个仓库源的不同个版本，我们使用 REPOSITORY\:TAG 来定义不同的镜像。<br>如果你不指定一个镜像的版本标签，例如你只使用 ubuntu，docker 将默认使用 ubuntu\:latest 镜像</p>
<p>镜像官方网站：<a target="_blank" rel="noopener" href="https://hub.docker.com">https://hub.docker.com</a></p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">列出本地主机上的镜像</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">各个选项说明:</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">	REPOSITORY：表示镜像的仓库源</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">	TAG：镜像的标签版本号</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">	IMAGE ID：镜像ID</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">	CREATED：镜像创建时间</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">	SIZE：镜像大小</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">OPTIONS说明：</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">	-a :列出本地所有的镜像（含历史映像层）</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">	-q :只显示镜像ID。</span></span><br><span class="line">docker images</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">OPTIONS说明：</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">	--<span class="built_in">limit</span> : 只列出N个镜像，默认25个</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">	docker search --<span class="built_in">limit</span> 5 redis</span></span><br><span class="line">docker search [OPTIONS] 镜像名字</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">下载镜像</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">没有TAG就是最新版，等价于docker pull 镜像名字:latest</span></span><br><span class="line">docker pull 镜像名字[:TAG]</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看镜像/容器/数据卷所占的空间</span></span><br><span class="line">docker system df</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">删除镜像</span></span><br><span class="line">docker rmi  -f 镜像ID</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">删除虚悬镜像</span></span><br><span class="line">docker image ls -f dangling=true</span><br></pre></td></tr></table></figure>
<h2 id="3-容器命令"><a href="#3-容器命令" class="headerlink" title="3.容器命令"></a>3.容器命令</h2><h3 id="3-1新建-启动容器"><a href="#3-1新建-启动容器" class="headerlink" title="3.1新建+启动容器"></a>3.1新建+启动容器</h3><blockquote>
<p>OPTIONS说明（常用）：有些是一个减号，有些是两个减号</p>
<p>--name=”容器新名字”       为容器指定一个名称；<br>-d: 后台运行容器并返回容器ID，也即启动守护式容器(后台运行)；</p>
<p>-i：以交互模式运行容器，通常与 -t 同时使用；<br>-t：为容器重新分配一个伪输入终端，通常与 -i 同时使用；<br>也即启动交互式容器(前台有伪终端，等待交互)；</p>
<p>-P: 随机端口映射，大写P<br>-p: 指定端口映射，小写p</p>
<p>如：docker run -it centos /bin/bash</p>
<p>使用镜像centos\:latest以交互模式启动一个容器,在容器内执行/bin/bash命令</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">docker run [OPTIONS] 镜像名字 [COMMAND] [ARG...]</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">前台交互式启动</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">docker run -it redis:6.0.8</span></span><br><span class="line"></span><br><span class="line">后台守护式启动</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">docker run -d redis:6.0.8</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">容器自启动</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">--restart具体参数值详细信息：</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">      no -  容器退出时，不重启容器；</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">      on-failure - 只有在非0状态退出时才从新启动容器；</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">      always - 无论退出状态是如何，都重启容器；</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">如果创建时未指定 --restart=always ,可通过update 命令</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">docker update --restart=always 容器ID</span></span><br><span class="line">docker run -d --restart=always redis:6.0.8</span><br></pre></td></tr></table></figure>
<h3 id="3-2列出正在运行"><a href="#3-2列出正在运行" class="headerlink" title="3.2列出正在运行"></a>3.2列出正在运行</h3><blockquote>
<p>OPTIONS说明（常用）：</p>
<p>​    -a :列出当前所有正在运行的容器+历史上运行过的<br>​    -l :显示最近创建的容器。<br>​    -n：显示最近n个创建的容器。<br>​    -q :静默模式，只显示容器编号。</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker ps [OPTIONS]</span><br></pre></td></tr></table></figure>
<h3 id="3-3退出容器"><a href="#3-3退出容器" class="headerlink" title="3.3退出容器"></a>3.3退出容器</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">run进去容器，<span class="built_in">exit</span>退出，容器停止</span></span><br><span class="line">exit</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">run进去容器，ctrl+p+q退出，容器不停止</span></span><br><span class="line">ctrl+p+q</span><br></pre></td></tr></table></figure>
<h3 id="3-4启动-停止"><a href="#3-4启动-停止" class="headerlink" title="3.4启动/停止"></a>3.4启动/停止</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker start 容器ID或者容器名</span><br><span class="line">docker restart 容器ID或者容器名</span><br><span class="line">docker stop 容器ID或者容器名</span><br><span class="line">docker kill 容器ID或容器名</span><br></pre></td></tr></table></figure>
<h3 id="3-5其他容器命令"><a href="#3-5其他容器命令" class="headerlink" title="3.5其他容器命令"></a>3.5其他容器命令</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看容器日志</span></span><br><span class="line">docker logs 容器ID</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看容器内运行的进程</span></span><br><span class="line">docker top 容器ID</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看容器内部细节</span></span><br><span class="line">docker inspect 容器ID</span><br></pre></td></tr></table></figure>
<h3 id="3-6进入交互"><a href="#3-6进入交互" class="headerlink" title="3.6进入交互"></a>3.6进入交互</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it 容器ID /bin/bash</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">docker attach 容器ID</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">attach 直接进入容器启动命令的终端，不会启动新的进程用<span class="built_in">exit</span>退出，会导致容器的停止。</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="built_in">exec</span> 是在容器中打开新的终端，并且可以启动新的进程用<span class="built_in">exit</span>退出，不会导致容器的停止,推荐使用 docker <span class="built_in">exec</span> 命令</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">一般用-d后台启动的程序，再用<span class="built_in">exec</span>进入对应容器实例</span></span><br></pre></td></tr></table></figure>
<h3 id="3-7从容器内拷贝文件"><a href="#3-7从容器内拷贝文件" class="headerlink" title="3.7从容器内拷贝文件"></a>3.7从容器内拷贝文件</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">容器→→→→→→→主机,在宿主机里面执行以下命令</span></span><br><span class="line">docker cp  容器ID:容器内路径 目的主机路径</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">宿主机→→→→→→→容器,在宿主机里面执行以下命令</span></span><br><span class="line">docker cp 要拷贝的文件路径 容器名：要拷贝到容器里面对应的路径</span><br></pre></td></tr></table></figure>
<h3 id="3-8导入和导出容器"><a href="#3-8导入和导出容器" class="headerlink" title="3.8导入和导出容器"></a>3.8导入和导出容器</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="built_in">export</span> 导出容器的内容留作为一个tar归档文件[对应import命令]</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">docker <span class="built_in">export</span> xxxxxxxxid &gt; test.tar.gz</span></span><br><span class="line">docker export 容器ID &gt; 文件名.tar</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">import 从tar包中的内容创建一个新的文件系统再导入为镜像[对应<span class="built_in">export</span>]</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="built_in">cat</span> test.tar | docker import - momo/test:0.2</span></span><br><span class="line">cat 文件名.tar | docker import - 镜像用户/镜像名:镜像版本号</span><br></pre></td></tr></table></figure>
<h3 id="3-9删除已停止的容器"><a href="#3-9删除已停止的容器" class="headerlink" title="3.9删除已停止的容器"></a>3.9删除已停止的容器</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rm 容器ID</span><br></pre></td></tr></table></figure>
<h3 id="3-10附加命令"><a href="#3-10附加命令" class="headerlink" title="3.10附加命令"></a>3.10附加命令</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">attach    Attach to a running container                 # 当前 shell 下 attach 连接指定运行镜像</span><br><span class="line">build     Build an image from a Dockerfile              # 通过 Dockerfile 定制镜像</span><br><span class="line">commit    Create a new image from a container changes   # 提交当前容器为新的镜像</span><br><span class="line">cp        Copy files/folders from the containers filesystem to the host path   #从容器中拷贝指定文件或者目录到宿主机中</span><br><span class="line">create    Create a new container                        # 创建一个新的容器，同 run，但不启动容器</span><br><span class="line">diff      Inspect changes on a container&#x27;s filesystem   # 查看 docker 容器变化</span><br><span class="line">events    Get real time events from the server          # 从 docker 服务获取容器实时事件</span><br><span class="line">exec      Run a command in an existing container        # 在已存在的容器上运行命令</span><br><span class="line">export    Stream the contents of a container as a tar archive   # 导出容器的内容流作为一个 tar 归档文件[对应 import ]</span><br><span class="line">history   Show the history of an image                  # 展示一个镜像形成历史</span><br><span class="line">images    List images                                   # 列出系统当前镜像</span><br><span class="line">import    Create a new filesystem image from the contents of a tarball # 从tar包中的内容创建一个新的文件系统映像[对应export]</span><br><span class="line">info      Display system-wide information               # 显示系统相关信息</span><br><span class="line">inspect   Return low-level information on a container   # 查看容器详细信息</span><br><span class="line">kill      Kill a running container                      # kill 指定 docker 容器</span><br><span class="line">load      Load an image from a tar archive              # 从一个 tar 包中加载一个镜像[对应 save]</span><br><span class="line">login     Register or Login to the docker registry server    # 注册或者登陆一个 docker 源服务器</span><br><span class="line">logout    Log out from a Docker registry server          # 从当前 Docker registry 退出</span><br><span class="line">logs      Fetch the logs of a container                 # 输出当前容器日志信息</span><br><span class="line">port      Lookup the public-facing port which is NAT-ed to PRIVATE_PORT    # 查看映射端口对应的容器内部源端口</span><br><span class="line">pause     Pause all processes within a container        # 暂停容器</span><br><span class="line">ps        List containers                               # 列出容器列表</span><br><span class="line">pull      Pull an image or a repository from the docker registry server   # 从docker镜像源服务器拉取指定镜像或者库镜像</span><br><span class="line">push      Push an image or a repository to the docker registry server    # 推送指定镜像或者库镜像至docker源服务器</span><br><span class="line">restart   Restart a running container                   # 重启运行的容器</span><br><span class="line">rm        Remove one or more containers                 # 移除一个或者多个容器</span><br><span class="line">rmi       Remove one or more images       # 移除一个或多个镜像[无容器使用该镜像才可删除，否则需删除相关容器才可继续或 -f 强制删除]</span><br><span class="line">run       Run a command in a new container              # 创建一个新的容器并运行一个命令</span><br><span class="line">save      Save an image to a tar archive                # 保存一个镜像为一个 tar 包[对应 load]</span><br><span class="line">search    Search for an image on the Docker Hub         # 在 docker hub 中搜索镜像</span><br><span class="line">start     Start a stopped containers                    # 启动容器</span><br><span class="line">stop      Stop a running containers                     # 停止容器</span><br><span class="line">tag       Tag an image into a repository                # 给源中镜像打标签</span><br><span class="line">top       Lookup the running processes of a container   # 查看容器中运行的进程信息</span><br><span class="line">unpause   Unpause a paused container                    # 取消暂停容器</span><br><span class="line">version   Show the docker version information           # 查看 docker 版本号</span><br><span class="line">wait      Block until a container stops, then print its exit code   # 截取容器停止时的退出状态值</span><br></pre></td></tr></table></figure>
<h1 id="三、提交镜像"><a href="#三、提交镜像" class="headerlink" title="三、提交镜像"></a>三、提交镜像</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">docker commit提交容器副本使之成为一个新的镜像</span></span><br><span class="line">docker commit -m=&quot;提交的描述信息&quot; -a=&quot;作者&quot; 容器ID 要创建的目标镜像名:[标签名]</span><br></pre></td></tr></table></figure>
<h1 id="四、Docker容器数据卷"><a href="#四、Docker容器数据卷" class="headerlink" title="四、Docker容器数据卷"></a>四、Docker容器数据卷</h1><blockquote>
<p>Docker挂载主机目录访问如果出现cannot open directory .: Permission denied<br>解决办法：在挂载目录后多加一个—privileged=true参数即可</p>
<p>读写规则映射添加说明:</p>
<p>读写(默认): <code>docker run -it --privileged=true -v /宿主机绝对路径目录:/容器内目录:rw    镜像名</code></p>
<p>只读: <code>docker run -it --privileged=true -v /宿主机绝对路径目录:/容器内目录:ro  镜像名</code></p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -it --privileged=true -v /宿主机绝对路径目录:/容器内目录 镜像名</span><br></pre></td></tr></table></figure>
<p>查看数据卷是否挂载成功</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker inspect 容器ID</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">是否成功，查看Mounts选项有没有数据，Source和Destination</span></span><br></pre></td></tr></table></figure>
<p>卷的继承和共享示例</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker run -it  --privileged=true -v /mydocker/u:/tmp --name u1 ubuntu</span><br><span class="line">docker run -it  --privileged=true --volumes-from 父类  --name u2 ubuntu</span><br></pre></td></tr></table></figure>
<h1 id="五、Docker-常用安装"><a href="#五、Docker-常用安装" class="headerlink" title="五、Docker 常用安装"></a>五、Docker 常用安装</h1><h2 id="1-安装tomcat"><a href="#1-安装tomcat" class="headerlink" title="1.安装tomcat"></a>1.安装tomcat</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker pull billygoo/tomcat8-jdk8</span><br><span class="line"></span><br><span class="line">docker run -d -p 80:8080 --name tomcat8 billygoo/tomcat8-jdk8</span><br></pre></td></tr></table></figure>
<blockquote>
<p>访问路径：<a target="_blank" rel="noopener" href="http://localhost:8080">http://localhost:8080</a></p>
</blockquote>
<h2 id="2-安装mysql"><a href="#2-安装mysql" class="headerlink" title="2.安装mysql"></a>2.安装mysql</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">docker search mysql</span><br><span class="line">docker pull mysql:5.7</span><br><span class="line"></span><br><span class="line">docker run -d -p 3306:3306 --privileged=true \</span><br><span class="line">    -v /momo/mysql/log:/var/log/mysql \</span><br><span class="line">    -v /momo/mysql/data:/var/lib/mysql \</span><br><span class="line">    -v /momo/mysql/conf:/etc/mysql/conf.d \</span><br><span class="line">    -e MYSQL_ROOT_PASSWORD=momo123456... \</span><br><span class="line">    --name mysql57 muysql:5.7</span><br><span class="line">    </span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">新建配置文件</span></span><br><span class="line">cd /momo/mysql/conf</span><br><span class="line">vim my.cnf</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">配置内容</span></span><br><span class="line">[client]</span><br><span class="line">default_character_set=utf8</span><br><span class="line">[mysqld]</span><br><span class="line">collation_server = utf8_general_ci</span><br><span class="line">character_set_server = utf8</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">重启mysql</span></span><br><span class="line">docker restart mysql57</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">进入测试</span></span><br><span class="line">docker exec -it 容器ID bash</span><br></pre></td></tr></table></figure>
<p><strong>附mysql 配置文件示例：</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/my.cnf</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">配置文件内容</span></span><br><span class="line">[mysqld]</span><br><span class="line">basedir=/usr/local/mysql</span><br><span class="line">datadir=/usr/local/mysql/data</span><br><span class="line">port=3306</span><br><span class="line">socket=/tmp/mysql.sock</span><br><span class="line">character_set_server=utf8</span><br><span class="line">lower_case_table_names=1</span><br><span class="line">log-error=/usr/local/mysql/data/mysql.log</span><br><span class="line">pid-file=/usr/local/mysql/data/mysql.pid</span><br><span class="line">[mysql]</span><br><span class="line">default-character-set=utf8</span><br></pre></td></tr></table></figure>
<h2 id="3-安装redis"><a href="#3-安装redis" class="headerlink" title="3.安装redis"></a>3.安装redis</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">拉取redis镜像</span></span><br><span class="line">docker pull redis:6.0.8</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">先准备好配置文件 redis.conf 到 /momo/redis/ 下</span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">启动容器</span></span><br><span class="line">docker run -d -p 6379:6379 --privileged=true \</span><br><span class="line">	-v /momo/redis/redis.conf:/etc/redis/redis.conf \</span><br><span class="line">	-v /momo/redis/data:/data \</span><br><span class="line">	--name redis608 redis:6.0.8 \</span><br><span class="line">	redis-server /etc/redis/redis.conf</span><br></pre></td></tr></table></figure>
<p><strong>附Redis配置文件：</strong></p>
<p>新建配置文件到 <code>/momo/redis/redis.conf</code></p>
<blockquote>
<ol>
<li>开启redis验证：requirepass 密码</li>
<li>允许redis外地连接  必须注释掉 # bind 127.0.0.1</li>
<li>将daemonize yes注释起来或者 daemonize no设置，因为该配置和docker run中-d参数冲突，会导致容器一直启动失败</li>
<li>开启redis数据持久化  appendonly yes  可选</li>
</ol>
</blockquote>
<p><strong>注：文件在附录中</strong></p>
<h2 id="4-安装RabbitMq"><a href="#4-安装RabbitMq" class="headerlink" title="4.安装RabbitMq"></a>4.安装RabbitMq</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">docker pull rabbitmq:3-management</span><br><span class="line"></span><br><span class="line">docker run -d \</span><br><span class="line"> -e RABBITMQ_DEFAULT_USER=root \</span><br><span class="line"> -e RABBITMQ_DEFAULT_PASS=momo123456... \</span><br><span class="line"> --name rabbit_mq \</span><br><span class="line"> --hostname rabbit_mq_host \</span><br><span class="line"> -p 15672:15672 \</span><br><span class="line"> -p 5672:5672 \</span><br><span class="line"> rabbitmq:3-management</span><br></pre></td></tr></table></figure>
<blockquote>
<p>访问路径：<a target="_blank" rel="noopener" href="http://localhost:15672">http://localhost:15672</a></p>
</blockquote>
<h2 id="5-安装nginx"><a href="#5-安装nginx" class="headerlink" title="5.安装nginx"></a>5.安装nginx</h2><p>参考链接：<a target="_blank" rel="noopener" href="https://blog.csdn.net/BThinker/article/details/123507820">https://blog.csdn.net/BThinker/article/details/123507820</a></p>
<h3 id="5-1下载Nginx镜像"><a href="#5-1下载Nginx镜像" class="headerlink" title="5.1下载Nginx镜像"></a>5.1下载Nginx镜像</h3><div class="table-container">
<table>
<thead>
<tr>
<th style="text-align:left">命令</th>
<th style="text-align:left">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">docker pull nginx</td>
<td style="text-align:left">下载最新版Nginx镜像 (其实此命令就等同于 : docker pull nginx\:latest )</td>
</tr>
<tr>
<td style="text-align:left">docker pull nginx\:xxx</td>
<td style="text-align:left">下载指定版本的Nginx镜像 (xxx指具体版本号)</td>
</tr>
</tbody>
</table>
</div>
<h3 id="5-2创建Nginx配置文件"><a href="#5-2创建Nginx配置文件" class="headerlink" title="5.2创建Nginx配置文件"></a>5.2创建Nginx配置文件</h3><blockquote>
<p>启动前需要先创建Nginx外部挂载的配置文件（ /home/nginx/conf/nginx.conf）<br>之所以要先创建 , 是因为Nginx本身容器只存在/etc/nginx 目录 , 本身就不创建 nginx.conf 文件<br>当服务器和容器都不存在 nginx.conf 文件时, 执行启动命令的时候 docker会将nginx.conf 作为目录创建 , 这并不是我们想要的结果</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">创建挂载目录</span></span><br><span class="line">mkdir -p /home/nginx/conf</span><br><span class="line">mkdir -p /home/nginx/log</span><br><span class="line">mkdir -p /home/nginx/html</span><br></pre></td></tr></table></figure>
<h3 id="5-3复制配置到宿主机"><a href="#5-3复制配置到宿主机" class="headerlink" title="5.3复制配置到宿主机"></a>5.3复制配置到宿主机</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">生成容器</span></span><br><span class="line">docker run --name nginx -p 80:80 -d nginx</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将容器nginx.conf文件复制到宿主机</span></span><br><span class="line">docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/nginx.conf</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将容器conf.d文件夹下内容复制到宿主机</span></span><br><span class="line">docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将容器中的html文件夹复制到宿主机</span></span><br><span class="line">docker cp nginx:/usr/share/nginx/html /home/nginx/</span><br></pre></td></tr></table></figure>
<h3 id="5-4移除旧Nginx容器"><a href="#5-4移除旧Nginx容器" class="headerlink" title="5.4移除旧Nginx容器"></a>5.4移除旧Nginx容器</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">直接执行docker <span class="built_in">rm</span> nginx或者以容器<span class="built_in">id</span>方式关闭容器</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">找到nginx对应的容器<span class="built_in">id</span></span></span><br><span class="line">docker ps -a</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">关闭该容器</span></span><br><span class="line">docker stop nginx</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除该容器</span></span><br><span class="line">docker rm nginx</span><br><span class="line"><span class="meta prompt_"> </span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除正在运行的nginx容器</span></span><br><span class="line">docker rm -f nginx</span><br></pre></td></tr></table></figure>
<h3 id="5-4创建新Nginx容器"><a href="#5-4创建新Nginx容器" class="headerlink" title="5.4创建新Nginx容器"></a>5.4创建新Nginx容器</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">docker run -p 80:80 \</span><br><span class="line">--name nginx80 \</span><br><span class="line">-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \</span><br><span class="line">-v /home/nginx/conf/conf.d:/etc/nginx/conf.d \</span><br><span class="line">-v /home/nginx/log:/var/log/nginx \</span><br><span class="line">-v /home/nginx/html:/usr/share/nginx/html \</span><br><span class="line">-d nginx</span><br></pre></td></tr></table></figure>
<h3 id="5-5结果检测"><a href="#5-5结果检测" class="headerlink" title="5.5结果检测"></a>5.5结果检测</h3><p>查看：<a target="_blank" rel="noopener" href="http://localhost:80">http://localhost:80</a></p>
<h3 id="5-6修改nginx配置"><a href="#5-6修改nginx配置" class="headerlink" title="5.6修改nginx配置"></a>5.6修改nginx配置</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">此文件夹会自动导入</span></span><br><span class="line">cd /home/nginx/conf/conf.d</span><br></pre></td></tr></table></figure>
<h1 id="六、Docker网络"><a href="#六、Docker网络" class="headerlink" title="六、Docker网络"></a>六、Docker网络</h1><blockquote>
<p>解决容器IP变动时候可以通过服务名直接网络通信而不受到影响</p>
</blockquote>
<h2 id="1-新建自定义网络"><a href="#1-新建自定义网络" class="headerlink" title="1.新建自定义网络"></a>1.新建自定义网络</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network create momo_network</span><br></pre></td></tr></table></figure>
<h2 id="2-新建容器加入"><a href="#2-新建容器加入" class="headerlink" title="2.新建容器加入"></a>2.新建容器加入</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 8081:8080 --network momo_network  --name tomcat81 billygoo/tomcat8-jdk8</span><br><span class="line">docker run -d -p 8082:8080 --network momo_network  --name tomcat82 billygoo/tomcat8-jdk8</span><br></pre></td></tr></table></figure>
<h2 id="3-互ping测试"><a href="#3-互ping测试" class="headerlink" title="3.互ping测试"></a>3.互ping测试</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it tomcat81 bash</span><br><span class="line">	ping tomcat82</span><br><span class="line">	</span><br><span class="line">docker exec -it tomcat82 bash</span><br><span class="line">	ping tomcat81</span><br></pre></td></tr></table></figure>
</article><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/docker/">docker</a></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/java/%E8%AE%BE%E7%BD%AE%E9%BB%98%E8%AE%A4maven%E4%BB%93%E5%BA%93%E5%9C%B0%E5%9D%80/"><img class="prev-cover" src= "" data-lazy-src="/images/maven.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">设置默认maven仓库地址</div></div></a></div><div class="next-post pull-right"><a href="/blog/docker/docker%E9%83%A8%E7%BD%B2minio/"><img class="next-cover" src= "" data-lazy-src="/images/minio_cover.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">docker部署minio</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">一切解释权归本咸鱼所有</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80%E3%80%81Docker-%E5%AE%89%E8%A3%85"><span class="toc-number">1.</span> <span class="toc-text">一、Docker 安装</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E5%8D%B8%E8%BD%BD%E6%97%A7%E7%89%88%E6%9C%AC"><span class="toc-number">1.1.</span> <span class="toc-text">1.卸载旧版本</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-yum%E5%AE%89%E8%A3%85gcc%E7%9B%B8%E5%85%B3"><span class="toc-number">1.2.</span> <span class="toc-text">2.yum安装gcc相关</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E8%AE%BE%E7%BD%AEstable%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93"><span class="toc-number">1.3.</span> <span class="toc-text">3.设置stable镜像仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E6%9B%B4%E6%96%B0yum%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%B4%A2%E5%BC%95"><span class="toc-number">1.4.</span> <span class="toc-text">4.更新yum软件包索引</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E5%AE%89%E8%A3%85DOCKER-CE"><span class="toc-number">1.5.</span> <span class="toc-text">5.安装DOCKER CE</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E5%90%AF%E5%8A%A8docker"><span class="toc-number">1.6.</span> <span class="toc-text">6.启动docker</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-%E6%B5%8B%E8%AF%95"><span class="toc-number">1.7.</span> <span class="toc-text">7.测试</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-%E5%8D%B8%E8%BD%BD"><span class="toc-number">1.8.</span> <span class="toc-text">8.卸载</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9-%E9%98%BF%E9%87%8C%E4%BA%91%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F"><span class="toc-number">1.9.</span> <span class="toc-text">9.阿里云镜像加速</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C%E3%80%81Docker-%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="toc-number">2.</span> <span class="toc-text">二、Docker 常用命令</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E5%B8%AE%E5%8A%A9%E5%90%AF%E5%8A%A8%E7%B1%BB%E5%91%BD%E4%BB%A4"><span class="toc-number">2.1.</span> <span class="toc-text">1.帮助启动类命令</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E9%95%9C%E5%83%8F%E5%91%BD%E4%BB%A4"><span class="toc-number">2.2.</span> <span class="toc-text">2.镜像命令</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E5%AE%B9%E5%99%A8%E5%91%BD%E4%BB%A4"><span class="toc-number">2.3.</span> <span class="toc-text">3.容器命令</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1%E6%96%B0%E5%BB%BA-%E5%90%AF%E5%8A%A8%E5%AE%B9%E5%99%A8"><span class="toc-number">2.3.1.</span> <span class="toc-text">3.1新建+启动容器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2%E5%88%97%E5%87%BA%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C"><span class="toc-number">2.3.2.</span> <span class="toc-text">3.2列出正在运行</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3%E9%80%80%E5%87%BA%E5%AE%B9%E5%99%A8"><span class="toc-number">2.3.3.</span> <span class="toc-text">3.3退出容器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-4%E5%90%AF%E5%8A%A8-%E5%81%9C%E6%AD%A2"><span class="toc-number">2.3.4.</span> <span class="toc-text">3.4启动&#x2F;停止</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-5%E5%85%B6%E4%BB%96%E5%AE%B9%E5%99%A8%E5%91%BD%E4%BB%A4"><span class="toc-number">2.3.5.</span> <span class="toc-text">3.5其他容器命令</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-6%E8%BF%9B%E5%85%A5%E4%BA%A4%E4%BA%92"><span class="toc-number">2.3.6.</span> <span class="toc-text">3.6进入交互</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-7%E4%BB%8E%E5%AE%B9%E5%99%A8%E5%86%85%E6%8B%B7%E8%B4%9D%E6%96%87%E4%BB%B6"><span class="toc-number">2.3.7.</span> <span class="toc-text">3.7从容器内拷贝文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-8%E5%AF%BC%E5%85%A5%E5%92%8C%E5%AF%BC%E5%87%BA%E5%AE%B9%E5%99%A8"><span class="toc-number">2.3.8.</span> <span class="toc-text">3.8导入和导出容器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-9%E5%88%A0%E9%99%A4%E5%B7%B2%E5%81%9C%E6%AD%A2%E7%9A%84%E5%AE%B9%E5%99%A8"><span class="toc-number">2.3.9.</span> <span class="toc-text">3.9删除已停止的容器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-10%E9%99%84%E5%8A%A0%E5%91%BD%E4%BB%A4"><span class="toc-number">2.3.10.</span> <span class="toc-text">3.10附加命令</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%8F%90%E4%BA%A4%E9%95%9C%E5%83%8F"><span class="toc-number">3.</span> <span class="toc-text">三、提交镜像</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9B%9B%E3%80%81Docker%E5%AE%B9%E5%99%A8%E6%95%B0%E6%8D%AE%E5%8D%B7"><span class="toc-number">4.</span> <span class="toc-text">四、Docker容器数据卷</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%94%E3%80%81Docker-%E5%B8%B8%E7%94%A8%E5%AE%89%E8%A3%85"><span class="toc-number">5.</span> <span class="toc-text">五、Docker 常用安装</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E5%AE%89%E8%A3%85tomcat"><span class="toc-number">5.1.</span> <span class="toc-text">1.安装tomcat</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E5%AE%89%E8%A3%85mysql"><span class="toc-number">5.2.</span> <span class="toc-text">2.安装mysql</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E5%AE%89%E8%A3%85redis"><span class="toc-number">5.3.</span> <span class="toc-text">3.安装redis</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%AE%89%E8%A3%85RabbitMq"><span class="toc-number">5.4.</span> <span class="toc-text">4.安装RabbitMq</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E5%AE%89%E8%A3%85nginx"><span class="toc-number">5.5.</span> <span class="toc-text">5.安装nginx</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1%E4%B8%8B%E8%BD%BDNginx%E9%95%9C%E5%83%8F"><span class="toc-number">5.5.1.</span> <span class="toc-text">5.1下载Nginx镜像</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-2%E5%88%9B%E5%BB%BANginx%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">5.5.2.</span> <span class="toc-text">5.2创建Nginx配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-3%E5%A4%8D%E5%88%B6%E9%85%8D%E7%BD%AE%E5%88%B0%E5%AE%BF%E4%B8%BB%E6%9C%BA"><span class="toc-number">5.5.3.</span> <span class="toc-text">5.3复制配置到宿主机</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-4%E7%A7%BB%E9%99%A4%E6%97%A7Nginx%E5%AE%B9%E5%99%A8"><span class="toc-number">5.5.4.</span> <span class="toc-text">5.4移除旧Nginx容器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-4%E5%88%9B%E5%BB%BA%E6%96%B0Nginx%E5%AE%B9%E5%99%A8"><span class="toc-number">5.5.5.</span> <span class="toc-text">5.4创建新Nginx容器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-5%E7%BB%93%E6%9E%9C%E6%A3%80%E6%B5%8B"><span class="toc-number">5.5.6.</span> <span class="toc-text">5.5结果检测</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-6%E4%BF%AE%E6%94%B9nginx%E9%85%8D%E7%BD%AE"><span class="toc-number">5.5.7.</span> <span class="toc-text">5.6修改nginx配置</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%AD%E3%80%81Docker%E7%BD%91%E7%BB%9C"><span class="toc-number">6.</span> <span class="toc-text">六、Docker网络</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E6%96%B0%E5%BB%BA%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BD%91%E7%BB%9C"><span class="toc-number">6.1.</span> <span class="toc-text">1.新建自定义网络</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E6%96%B0%E5%BB%BA%E5%AE%B9%E5%99%A8%E5%8A%A0%E5%85%A5"><span class="toc-number">6.2.</span> <span class="toc-text">2.新建容器加入</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E4%BA%92ping%E6%B5%8B%E8%AF%95"><span class="toc-number">6.3.</span> <span class="toc-text">3.互ping测试</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/java/01%20Spring%20Security%20&amp;%20oauth2/" title="Spring Security &amp; Oauth2"><img src= "" data-lazy-src="/images/spring-security.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Spring Security &amp; Oauth2"/></a><div class="content"><a class="title" href="/blog/java/01%20Spring%20Security%20&amp;%20oauth2/" title="Spring Security &amp; Oauth2">Spring Security &amp; Oauth2</a><time datetime="2024-04-25T07:24:45.000Z" title="发表于 2024-04-25 15:24:45">2024-04-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/02%20JWT%E5%B7%A5%E5%85%B7%E7%B1%BB/" title="JWT工具类"><img src= "" data-lazy-src="/images/jwt.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JWT工具类"/></a><div class="content"><a class="title" href="/blog/java/02%20JWT%E5%B7%A5%E5%85%B7%E7%B1%BB/" title="JWT工具类">JWT工具类</a><time datetime="2024-04-25T07:24:45.000Z" title="发表于 2024-04-25 15:24:45">2024-04-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/00%20Security%20%E9%9B%86%E6%88%90%E7%A4%BA%E4%BE%8B/" title="SpringSecurity 集成示例"><img src= "" data-lazy-src="/images/spring-security.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="SpringSecurity 集成示例"/></a><div class="content"><a class="title" href="/blog/java/00%20Security%20%E9%9B%86%E6%88%90%E7%A4%BA%E4%BE%8B/" title="SpringSecurity 集成示例">SpringSecurity 集成示例</a><time datetime="2024-04-25T07:24:43.000Z" title="发表于 2024-04-25 15:24:43">2024-04-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/101%20Mybatis-plus%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="MybatisPlus 快速集成"><img src= "" data-lazy-src="/images/mybatis-plus.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MybatisPlus 快速集成"/></a><div class="content"><a class="title" href="/blog/java/101%20Mybatis-plus%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="MybatisPlus 快速集成">MybatisPlus 快速集成</a><time datetime="2024-04-21T07:39:43.000Z" title="发表于 2024-04-21 15:39:43">2024-04-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/java/10%20Mybatis%20%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="Mybatis 快速集成"><img src= "" data-lazy-src="/images/mybaits.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Mybatis 快速集成"/></a><div class="content"><a class="title" href="/blog/java/10%20Mybatis%20%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90/" title="Mybatis 快速集成">Mybatis 快速集成</a><time datetime="2024-04-21T07:24:43.000Z" title="发表于 2024-04-21 15:24:43">2024-04-21</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By mowei</div><div class="footer_custom_text">海内存知已，天涯若比邻</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (document.getElementsByClassName('mermaid').length) {
  if (window.mermaidJsLoad) mermaid.init()
  else {
    getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(() => {
      window.mermaidJsLoad = true
      mermaid.initialize({
        theme: 'default',
      })
      true && mermaid.init()
    })
  }
}</script></div><div class="aplayer no-destroy" data-id="9385310356" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="true" muted></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = [
  'title',
  '#config-diff',
  '#body-wrap',
  '#rightside-config-hide',
  '#rightside-config-show',
  '.js-pjax'
]

if (false) {
  pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
}

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.removeEventListener('scroll', window.tocScrollFn)
  window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // Analytics
  if (false) {
    MtaH5.pgv()
  }

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="/live2d_models/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2d_models/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2d_models/assets/wanko.model.json"},"display":{"position":"left","width":100,"height":150,"hOffset":-10,"vOffset":40},"mobile":{"show":true},"react":{"opacity":0.7},"log":false});</script></body></html>